package com.tanhua.app.service;


import com.tanhua.api.mongo.PublishApi;
import com.tanhua.domain.mogo.Publish;
import com.tanhua.domain.vo.UserHolder;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class QuanZiMqService {
    @Reference
    private PublishApi publishApi;

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    //生产用户行为数据 添加到map中 并发送到消息中间件
    public void SetMsg(String publishId, int type) {
        //获取当前用户id
        Long userId = UserHolder.getUser().getId();
        //创建map集合
        Map map = new HashMap();
        map.put("userId", userId);
        map.put("publishId", publishId);
        map.put("type", type);

        //查询并 封装大数据推荐所需要的pid
        Publish publish = publishApi.findByIdtoPublish(publishId);

        map.put("pid", publish.getId());

        //发送消息到消息队列
        rocketMQTemplate.convertAndSend("tanhuan_quanzi", map);
        System.out.println("已向消息中间件中发送用户行为消息");

    }

}
